package com.mkz.jbpm.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mkz.core.common.util.ResponseResult;
import com.mkz.core.log.annotation.SysLog;
import com.mkz.jbpm.entity.TaskFlow;
import com.mkz.jbpm.service.TaskFlowService;

import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 流程流转记录
 *
 * @author KuangJianyu
 * @date 2020-04-08 17:24:29
 */
@RestController
@AllArgsConstructor
@RequestMapping("/taskflow" )
@Api(value = "taskflow", tags = "流程流转记录管理")
public class TaskFlowController {

    private final  TaskFlowService taskFlowService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param taskFlow 流程流转记录
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    public ResponseResult getTaskFlowPage(Page page, TaskFlow taskFlow) {
        return ResponseResult.ok(taskFlowService.page(page, Wrappers.query(taskFlow)));
    }


    /**
     * 通过id查询流程流转记录
     * @param id id
     * @return ResponseResult
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    public ResponseResult getById(@PathVariable("id" ) String id) {
        return ResponseResult.ok(taskFlowService.getById(id));
    }

    /**
     * 新增流程流转记录
     * @param taskFlow 流程流转记录
     * @return ResponseResult
     */
    @ApiOperation(value = "新增流程流转记录", notes = "新增流程流转记录")
    @SysLog("新增流程流转记录" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('jbpm_taskflow_add')" )
    public ResponseResult save(@RequestBody TaskFlow taskFlow) {
        return ResponseResult.ok(taskFlowService.save(taskFlow));
    }

    /**
     * 修改流程流转记录
     * @param taskFlow 流程流转记录
     * @return ResponseResult
     */
    @ApiOperation(value = "修改流程流转记录", notes = "修改流程流转记录")
    @SysLog("修改流程流转记录" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('jbpm_taskflow_edit')" )
    public ResponseResult updateById(@RequestBody TaskFlow taskFlow) {
        return ResponseResult.ok(taskFlowService.updateById(taskFlow));
    }

    /**
     * 通过id删除流程流转记录
     * @param id id
     * @return ResponseResult
     */
    @ApiOperation(value = "通过id删除流程流转记录", notes = "通过id删除流程流转记录")
    @SysLog("通过id删除流程流转记录" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('jbpm_taskflow_del')" )
    public ResponseResult removeById(@PathVariable String id) {
        return ResponseResult.ok(taskFlowService.removeById(id));
    }

}
